package top.houry.test;

import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.stub.StreamObserver;
import top.houry.grpc.proto.OpenAPIGrpc;
import top.houry.grpc.proto.TestGrpc;


public class SingleRpcServer {
    public static void main(String[] args) throws Exception {
        Server server = ServerBuilder.forPort(9999).addService(new SingleRpc()).build();
        server.start();
        server.awaitTermination();
    }

}


class SingleRpc extends OpenAPIGrpc.OpenAPIImplBase {
    @Override
    public void singleRequest(TestGrpc.Request request, StreamObserver<TestGrpc.Response> responseObserver) {
        System.out.println("接收到请求:" + request.getName());
        TestGrpc.Response response = TestGrpc.Response.newBuilder().setMessage("您好 " + request.getName() + ", 单一请求").build();
        responseObserver.onNext(response);
        responseObserver.onCompleted();
    }
}
